//
//  LXGiftDigitLabel.swift
//  礼物动画展示
//
//  Created by seven on 2017/12/29.
//  Copyright © 2017年 seven. All rights reserved.
//

import UIKit

class LXGiftDigitLabel: UILabel {
    
    override func drawText(in rect: CGRect) {
        //1.获取图形上下文
        let context = UIGraphicsGetCurrentContext()
        //2.给上下文线段设置一个宽度，通过该宽度画出文本
        context?.setLineWidth(5)
        context?.setLineJoin(.round)
        context?.setTextDrawingMode(.stroke)
        textColor = .orange
        super.drawText(in: rect)
        
        context?.setTextDrawingMode(.fill)
        textColor = UIColor.white
        super.drawText(in: rect)
    }
    
    func showDigitalAnimation(_ completeion: @escaping () -> ()){
        UIView.animateKeyframes(withDuration: 0.25, delay: 0, options: [], animations: {
            UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.7, animations: {
                self.transform = CGAffineTransform(scaleX: 3.0, y: 3.0)
            })
            UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5, animations: {
                self.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
            })
        }) { (isFinish) in
            UIView.animate(withDuration: 0.25, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 10, options: [], animations: {
                self.transform = CGAffineTransform.identity
            }, completion: { (isFinish) in
                completeion()
            })
        }
        
//        UIView.animate(withDuration: 0.25, animations: {
//            self.transform = CGAffineTransform(scaleX: 3.0, y: 3.0)
//        }) { (isFinish) in
//            UIView.animate(withDuration: 0.1, animations: {
//                self.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
//            }, completion: { (isFinish) in
//                UIView.animate(withDuration: 0.25, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 10, options: [], animations: {
//                    self.transform = CGAffineTransform.identity
//                }, completion: { (isFinish) in
//                    completeion()
//                })
//            })
//        }
    }
}
